@ECHO OFF

ECHO CREATING DIRECTORIES FOR DVD...
MKDIR D:\winpe_x86\ISO
MKDIR D:\winpe_x86\mount
MKDIR D:\winpe_x86\ISO\sources
MKDIR D:\winpe_x86\ISO\boot
MKDIR D:\winpe_x86\ISO\EFI

ECHO COPYING DATA TO DIRECTORIES...
XCOPY /Y /Q D:\imagex\Tools\PETools\x86\bootmgr d:\winpe_x86\ISO
XCOPY /Y /Q D:\imagex\Tools\PETools\x86\boot\etfsboot.com D:\winpe_x86
XCOPY /E /Y /Q D:\imagex\Tools\PETools\x86\boot D:\winpe_x86\ISO\boot
XCOPY /E /Y /Q D:\imagex\Tools\PETools\x86\EFI D:\winpe_x86\ISO\EFI

XCOPY /Y /Q D:\imagex\Tools\PETools\x86\winpe.wim D:\winpe_x86
COPY /Y D:\imagex\Tools\PETools\x86\winpe.wim D:\winpe_x86\ISO\sources\boot.wim

D:\imagex\Tools\x86\imagex.exe /mountrw D:\winpe_x86\winpe.wim 1 D:\winpe_x86\mount

ECHO COPYING EXTRA DATA TO BOOTABLE IMAGE...
XCOPY /E /Y /Q D:\imagex\Tools\Servicing D:\winpe_x86\mount\Windows
XCOPY /E /Y /Q D:\imagex\Tools\x86 D:\winpe_x86\mount\Windows
XCOPY /Y /Q D:\imagex\Tools\PETools\x86\bootsect.exe D:\winpe_x86\mount\Windows\System32
DEL /Q D:\winpe_x86\ISO\boot\bootfix.bin

REM ECHO.
REM D:\imagex\Tools\PETools\peimg.exe /inf="D:\imagex\Drivers\Intel NIC\*.inf" D:\winpe_x86\mount\Windows

ECHO.
ECHO COPYING CUSTOM SCRIPTS DIRECTORY TO BOOTABLE IMAGE...
XCOPY /E /Y "D:\imagex\custom scripts" D:\winpe_x86\mount\Windows\System32
DEL /Q D:\winpe_x86\mount\Windows\System32\excludes.ini
DEL /Q D:\winpe_x86\mount\Windows\System32\GUIImageX.exe
DEL /Q D:\winpe_x86\mount\Windows\System32\GUIImageX.ini
XCOPY /Y /Q D:\winpe_x86\mount\Windows\System32\startrestore.cmd D:\winpe_x86\mount\Windows\System32\startnet.cmd
DEL /Q D:\winpe_x86\mount\Windows\System32\startrestore.cmd

REM ECHO.
REM ECHO PLEASE ENSURE THAT THE .WIM FILE YOU WISH TO ADD TO THIS IMAGE
REM ECHO IS IN THE D:\IMAGEX FOLDER
REM PAUSE
REM ECHO COPYING .WIM FILE...
REM XCOPY /Y /Q D:\imagex\*.wim D:\winpe_x86\mount

ECHO.
ECHO SAVING AND UNMOUNTING MODIFIED IMAGE...
D:\imagex\Tools\PETools\peimg.exe /prep /f D:\winpe_x86\mount\Windows
D:\imagex\Tools\x86\imagex.exe /unmount /commit D:\winpe_x86\mount
D:\imagex\Tools\x86\imagex.exe /boot /export D:\winpe_x86\winpe.wim 1 D:\winpe_x86\final.wim

ECHO CREATING FINAL IMAGE...
XCOPY /Y /Q D:\winpe_x86\final.wim D:\winpe_x86\ISO\sources\boot.wim
D:\imagex\Tools\PETools\oscdimg.exe -n -lImageX -o -m -h -bD:\winpe_x86\etfsboot.com D:\winpe_x86\ISO D:\winpe_x86\imagex.iso
COPY /Y D:\winpe_x86\imageX.iso D:\restore.iso
RMDIR /Q /S D:\winpe_x86

ECHO COMPLETED CREATION OF BOOTABLE RESTORE DVD
ECHO IMAGE IS STORED AT D:\RESTORE.ISO
PAUSE
EXIT